<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" value="改变背景颜色" onclick="changeBack()">
    <script>
        var arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']

        function gerRandom(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }

        function getColor() {
            var str = "#";
            for (var i = 0; i < 6; i++) {
                var re = arr[gerRandom(0, arr.length - 1)];
                str += re;
            }
            return str;
        }
        // console.log(getColor());
        function changeBack() {
            var body = document.getElementsByTagName('body');
            body[0].style.backgroundColor = getColor()
        }
    </script>
</body>

</html>